package com.xu.cloud.common.auth;

import org.springframework.core.NamedThreadLocal;

/**
 * 本地线程缓存用户认证授权上下文
 *
 * @author xuguan
 * @since 2025/1/10
 */
public class AuthContextHolder {
    private static final ThreadLocal<AuthContext> authContextHolder = new NamedThreadLocal<>("authContext");

    public static void setAuthContext(AuthContext authContext) {
        authContextHolder.set(authContext);
    }

    public static AuthContext getAuthContext() {
        return authContextHolder.get();
    }

    public static void removeAuthContext() {
        authContextHolder.remove();
    }
}
